﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace L02
{
    class Array
    {
        public int[] arr = new int[100];
        public int x;

        public void Output()
        {
            Console.WriteLine("数组输出如下：");
            for (x = 0; x <= arr.Length - 1; x++)
            {
                Console.Write("{0}  ", arr[x]);
            }
            Console.WriteLine();
        }

        public void Search(int i)
        {
            for (x = 0; x <= arr.Length - 1; x++)
            {
                if (arr[x] == i) break;
            }
            if (x < arr.Length) Console.WriteLine("位置为：{0}", x);
            else Console.WriteLine("不在查找范围内");
        }

        public void InsertSort()
        {
            for (int i = 1; i < arr.Length; i++)
            {
                int temp = arr[i];
                int j = i - 1;
                while (temp < arr[j])
                {
                    arr[j + 1] = arr[j];
                    j--;
                    if (j == -1) break;
                }
                arr[j + 1] = temp;
            }
        }

        class Program
        {
            static void Main(string[] args)
            {
                Array array = new Array();
                array.arr = new int[10] { 6, 9, 5, 11, 42, 0, 6, 7, 3, 2 };
                array.Output();
                Console.Write("请输入需要查找的数字：");
                int t = Convert.ToInt32(Console.ReadLine());//从键盘输入
                array.Search(t);
                Console.Write("数组进行插入排序后，");
                array.InsertSort();
                array.Output();
                Console.ReadKey();
            }
        }
    }
}


